﻿#include<iostream>
using namespace std;
template<typename T1>
T1 ave1(T1 a, T1 b) {
	return (a + b) / 2;
}
template<typename T1, typename T2>
T1 ave2(T2 a, T1 b) {
	return (a + b) / 2;
}
template<typename TR, typename T1, typename T2>
TR ave3(T1 a, T2 b, int c = 200) {//使用和平时的函数一样
	T1 x;
	T2* px;
	return (a + b) / 2;
}

template<typename T1, typename T2>
decltype(auto) bigger(T1& a, T2& b) {//只有在T1和T2的数据类型相同，也就是不能在有类型转换的时候，才能传引用出来
	return a > b ? a : b;
}

int main() {
	cout << ave1(200, 200) << endl;

	cout << ave2(200.01f, 200) << endl;
	cout << ave2<float>(100, 200.01f) << endl;//指定T1为float
	cout << ave2<float, int>(100, 200.01f) << endl;//指定T1为float,T2为int

	cout << ave3<int, float, double>(100, 200.01f) << endl;
	cout << ave3<double>(100, 200.01f) << endl;//指定TR为double

	int a = 50;
	int b = 5000000;
	cout << bigger(a, b) << endl;
	bigger(a, b) = -1;
	cout << b << endl;
}